﻿using Prism.Commands;
using Prism.Ioc;
using Prism.Mvvm;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WPFStudy.PrismStudy.Views;

namespace WPFStudy.PrismStudy.ViewModels
{
    public class RegionStudyViewModel:BindableBase
    {
        private IRegionManager _regionManager;
        public  RegionStudyViewModel(IRegionManager regionManager, IContainerExtension containerManager)
        {
            //IRegion region = regionManager.Regions["ContentRegion"];
            //ContentControlViewA view = containerManager.Resolve<ContentControlViewA>();
            //IRegionManager scopedRegion = region.Add(view,null,true);
            _regionManager = regionManager;
            var v = containerManager.Resolve<ContentControlViewA>();
        }

        #region 切换区域

        /// <summary>
        /// 切换区域 - 命令
        /// </summary>
        private DelegateCommand<string> _switchRegionCmd;

        /// <summary>
        /// 切换区域 - 命令
        /// </summary>
        public DelegateCommand<string> SwitchRegionCmd =>
            _switchRegionCmd ?? (_switchRegionCmd = new DelegateCommand<string>(ExecuteSwitchRegion));

        /// <summary>
        /// 执行 - 切换区域
        /// </summary>    
        void ExecuteSwitchRegion(string parameter)
        {
            switch (parameter)
            {
                case "A":
                    RegionContent = new ContentControlViewA();
                    break;
                case "B":
                    RegionContent = new ContentControlViewB();
                    break;
                case "C":
                    RegionContent = new ContentControlViewC();
                    break;
            }
        }

        #endregion 切换区域


        #region 命令

        /// <summary>
        /// 命令 - 命令
        /// </summary>
        private DelegateCommand<string> _openRegionCmd;

        /// <summary>
        /// 命令 - 命令
        /// </summary>
        public DelegateCommand<string> OpenRegionCmd =>
            _openRegionCmd ?? (_openRegionCmd = new DelegateCommand<string>(ExecuteOpenRegion));

        /// <summary>
        /// 执行 - 命令
        /// </summary>    
        void ExecuteOpenRegion(string parameter)
        {
            _regionManager.Regions["ContentRegion"].RequestNavigate(parameter);
        }

        #endregion 命令

        #region 区域内容

        /// <summary>
        /// 区域内容
        /// </summary>
        private object _regionContent;

        /// <summary>
        /// 区域内容
        /// </summary>
        public object RegionContent
        {
            get { return _regionContent; }
            set { SetProperty(ref _regionContent, value); }
        }

        #endregion 区域内容 
    }
}
